* ***************************************************************** *
* ***************************************************************** *
* Date: 2/7/2018 *
* Author: JAKUB LYSEK*
* DATA AND MODELS FOR THE MANUSCRIPT:
* "TURNING OUT BUT NOT VOTING: Invalid Ballots in Post-Communist Parliamentary Elections"
* Input File: POSTCOM_INVALIDS.dta *
* Output File: POSTCOM_INVALIDS.log *
* **************************************************************** *
* **************************************************************** *

*SOURCE FILE IN YOUR DEPOSITORY*
*change the pathway in the code
use "\POSTCOM_INVALIDS.dta", clear
log using "\POSTCOM_INVALIDS.log"

*********************
*DATASET PREPARATION*
*********************
*run this code before running models
set more off 
encode Country, generate(Country_name)
xtset Country_name panel

*generating interactions*
gen FHAVScore_ENPP = FHAVScore*Effectivenumberofparliamentarypa
gen Concurence_Literacy = Concurrenceelections*Literacyrate
gen MMS_Literacy = MMS*Literacyrate
gen IntDemTrad_Year = IntDemTradition*Y_after_First_elections
gen Corr_Eth = TCI_index*EthFrac
gen VDEM_COR_Eth = VDEM_COR*EthFrac

*generating lagged - variables*
sort id panel 
by id: gen lagInvalidvotes = Invalidvotes[_n-1]
by id: gen lagInvalidvotes_againstall = Invalidvotes_againstall[_n-1]
by id: gen lagEffeparPa = Effectivenumberofparliamentarypa[_n-1]
*generating dynamic change of ENPP (Cohen 2018)
gen dyn_EffparPa =(Effectivenumberofparliamentarypa-lagEffeparPa)/Effectivenumberofparliamentarypa

*generating separate ballot dummy
gen sep_ballot =  CZK + SVK + Lithuania
*PLEASE FIND VARIABLE CODING AT THE END OF THE DOFILE

************************************************************************************************************************************************************************
***********************MODELS*******************************************************************************************************************************************
************************************************************************************************************************************************************************

*Hypothesis 1: Disproportional electoral systems are associated with higher level of invalid votes.
*Hypothesis 2a:  Ballot complexity is positively associated with invalid votes.
*Hypothesis 2b:  Concurrent elections increases invalid ballots. 
*Hypothesis 3: The higher the share of urban and well educated population the lower the invalid votes.
*Hypothesis 4: Poor performing economy is positively associated with invalid voting.
*Hypothesis 6a: Parliamentary fragmentation increases invalid voting.
*Hypothesis 6b: Parliamentary fragmentation increases invalid voting more in countries with a lower level of the quality of democracy than in more democratic ones.
*Hypothesis 7: The closest the electoral race the less incidence of invalid votes

******************************************
*DV> Invalidvotes_againstall**************
******************************************
*For the models including Ukraine and Russia = against all votes counted together with invalids


***FINAL MODEL IN THE PAPER: TURNING OUT BUT NOT VOTING IN TABLE 2***
*********************************************************************************************************************************************************************************************************************
*ALL DATA
xtpcse Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections   FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE_ALL
xtpcse Invalidvotes_againstall lagInvalidvotes MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE_Lagged_ALL
xtpcse Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
estimates store PraisWinsten_ALL
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store FIXED_ALL
xtreg Invalidvotes_againstall Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP MMS Concurrenceelections sep_ballot GDPgrowthin Literacyrate Urbanpopulation Year LogGDP_per_capita Giniindex Unemployment Votedifferential1th2thin TheleastsquaresindexLSq EarlyElections First_election, fe
estimates store INTERACTION
*EU ONLY
xtpcse Invalidvotes  FHAVScore MMS First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1 , pairwise
estimates store XTPCSE_EU
xtpcse Invalidvotes lagInvalidvotes MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1, pairwise
estimates store XTPCSE_Lagged_EU
xtpcse Invalidvotes  FHAVScore MMS First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1, hetonly corr(ar1)
estimates store PraisWinsten_EU
xtreg Invalidvotes  FHAVScore MMS First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1, fe
estimates store FIXED_EU
estout XTPCSE_ALL XTPCSE_Lagged_ALL PraisWinsten_ALL FIXED_ALL INTERACTION XTPCSE_EU XTPCSE_Lagged_EU PraisWinsten_EU FIXED_EU, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N)

*FINAL TABLE 2*
***************
estout XTPCSE_ALL XTPCSE_Lagged_ALL PraisWinsten_ALL FIXED_ALL XTPCSE_EU XTPCSE_Lagged_EU PraisWinsten_EU FIXED_EU, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N)
*estout package has to be installed
*********************************************************************************************************************************************************************************************************************
*********************************************************************************************************************************************************************************************************************

*INTERACTION_FHxEFNP * not shown in the paper
*ALL DATA
xtpcse Invalidvotes_againstall  Effectivenumberofparliamentarypa  FHAVScore FHAVScore_ENPP First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq  Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE_ALL
xtpcse Invalidvotes_againstall lagInvalidvotes  FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE_Lagged_ALL
xtpcse Invalidvotes_againstall FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
estimates store PraisWinsten_ALL
xtreg Invalidvotes_againstall FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store FIXED_ALL
*EU ONLY
xtpcse Invalidvotes  FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1 , pairwise
estimates store XTPCSE_EU
xtpcse Invalidvotes lagInvalidvotes FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1, pairwise
estimates store XTPCSE_Lagged_EU
xtpcse Invalidvotes FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1, hetonly corr(ar1)
estimates store PraisWinsten_EU
xtreg Invalidvotes FHAVScore_ENPP FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1, fe
estimates store FIXED_EU
estout XTPCSE_ALL XTPCSE_Lagged_ALL PraisWinsten_ALL FIXED_ALL XTPCSE_EU XTPCSE_Lagged_EU PraisWinsten_EU FIXED_EU, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N)

*Marginal effect plot code (see Golder http://mattgolder.com/interactions )
* run one of the above regression models and then run the code:
xtreg Invalidvotes_againstall Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP MMS sep_ballot Concurrenceelections GDPgrowthin Literacyrate Urbanpopulation Year IntDemTradition LogGDP_per_capita Giniindex  Votedifferential1th2thin TheleastsquaresindexLSq EarlyElections First_election, fe
generate MV=((_n+4)/5)
replace  MV=. if _n>31
matrix b=e(b)
matrix V=e(V) 
scalar b1=b[1,1]
scalar b2=b[1,2]
scalar b3=b[1,3]
scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]
scalar covb1b3=V[1,3]
scalar covb2b3=V[2,3]
scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3
gen conb=b1+b3*MV if _n<1564
gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<100
gen a=1.96*conse 
gen upper=conb+a 
gen lower=conb-a
graph twoway line conb   MV, clwidth(medium) clcolor(blue) clcolor(black)   ||   line upper  MV, clpattern(dash) clwidth(thin) clcolor(black)   ||   line lower  MV, clpattern(dash) clwidth(thin) clcolor(black)   ||   ,      xlabel(1 2 3 4 5 6 7, labsize(2.5))     ylabel(0 0.5 1 1.5 2, labsize(2.5))     yscale(noline) xscale(noline)    legend(col(1) order(1 2) label(1 "Marginal Effect of ENPP")      label(2 "95% Confidence Interval")   label(3 " "))  yline(0, lcolor(black))   xtitle( Freedom House Score, size(3)  )   xsca(titlegap(2))   ysca(titlegap(2))    ytitle("Marginal Effect of ENPP", size(3))  scheme(s2mono) graphregion(fcolor(white))

drop MV conb conse a upper lower
*if you want to repeat the command to produce marginal plot, drop those newly generated variables

*KEY VARIABLE MODELS
********************
xtpcse Invalidvotes  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, pairwise
estimates store XTPCSE
xtpcse Invalidvotes lagInvalidvotes  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, pairwise
estimates store XTPCSE_Lagged
xtpcse Invalidvotes  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, hetonly corr(ar1)
estimates store PraisWinsten
xtreg Invalidvotes  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, fe
estimates store FIXED
xtpcse Invalidvotes_againstall  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, pairwise
estimates store XTPCSE_ALL
xtpcse Invalidvotes_againstall lagInvalidvotes  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, pairwise
estimates store XTPCSE_Lagged_ALL
xtpcse Invalidvotes_againstall  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, hetonly corr(ar1)
estimates store PraisWinsten_ALL
xtreg Invalidvotes_againstall  FHAVScore  Concurrenceelections TheleastsquaresindexLSq Effectivenumberofparliamentarypa  GDPgrowthin Literacyrate Urbanpopulation, fe
estimates store FIXED_ALL
estout XTPCSE XTPCSE_Lagged PraisWinsten FIXED XTPCSE_ALL XTPCSE_Lagged_ALL PraisWinsten_ALL FIXED_ALL, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2)


****MIXED MODELS**********
**************************
***Mixed models with random country intercept
*install mltrsq  package to compute 1_level and 2_level R2
xtmixed Invalidvotes_againstall || id:
iccvar
*intraclass correlation is 0,37 (37% between countries variance, 63% within countries variance)
estimates store NULL
xtmixed Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections || id:
mltrsq 
estimates store INSTITUTIONAL
xtmixed Invalidvotes_againstall FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin || id:
mltrsq 
estimates store POLITICAL 
xtmixed Invalidvotes_againstall Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation || id:
mltrsq
estimates store SOCIOECONOMIC 
xtmixed Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections   FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year || id:
mltrsq
estimates store FULL
estout NULL INSTITUTIONAL POLITICAL SOCIOECONOMIC FULL, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(N N_l2 aic bic ll sb_rsq_l1 sb_rsq_l2 br_rsq_l1 br_rsq_l2)

*ONLY EU COUNTRIES*
xtmixed Invalidvotes_againstall if  EUmember==1 || id:
iccvar
estimates store NULL
xtmixed Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections if  EUmember==1 || id:
mltrsq 
estimates store INSTITUTIONAL
xtmixed Invalidvotes_againstall FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin if  EUmember==1 || id:
mltrsq 
estimates store POLITICAL 
xtmixed Invalidvotes_againstall Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation if  EUmember==1 || id:
mltrsq
estimates store SOCIOECONOMIC 
xtmixed Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections   FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year if  EUmember==1 || id:
mltrsq
estimates store FULL
estout NULL INSTITUTIONAL POLITICAL SOCIOECONOMIC FULL, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(N N_l2 aic bic ll sb_rsq_l1 sb_rsq_l2 br_rsq_l1 br_rsq_l2)







***** MODELS FOR Referee’s Report E ****
** ADDING NEW VARIABLES, CORRUPTION AND ETHNIC FRAGMENTATION
*ALL DATA
xtpcse Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections   FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout, pairwise
estimates store XTPCSE_ALL
xtpcse Invalidvotes_againstall lagInvalidvotes MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout, pairwise
estimates store XTPCSE_Lagged_ALL
xtpcse Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout, hetonly corr(ar1)
estimates store PraisWinsten_ALL
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout, fe
estimates store FIXED_ALL
xtreg Invalidvotes_againstall Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP MMS Concurrenceelections sep_ballot GDPgrowthin Literacyrate Urbanpopulation Year LogGDP_per_capita Giniindex Unemployment Votedifferential1th2thin TheleastsquaresindexLSq EarlyElections First_election TCI_index EthFrac Turnout, fe
estimates store INTERACTION
*EU ONLY
xtpcse Invalidvotes  FHAVScore MMS First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout if  EUmember==1 , pairwise
estimates store XTPCSE_EU
xtpcse Invalidvotes lagInvalidvotes MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout if  EUmember==1, pairwise
estimates store XTPCSE_Lagged_EU
xtpcse Invalidvotes  FHAVScore MMS First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout if  EUmember==1, hetonly corr(ar1)
estimates store PraisWinsten_EU
xtreg Invalidvotes  FHAVScore MMS First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year TCI_index EthFrac Turnout if  EUmember==1, fe
estimates store FIXED_EU
estout XTPCSE_ALL XTPCSE_Lagged_ALL PraisWinsten_ALL FIXED_ALL INTERACTION XTPCSE_EU XTPCSE_Lagged_EU PraisWinsten_EU FIXED_EU, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N)

*FINAL TABLE FOR Referee’s Report E *
***************
estout XTPCSE_ALL XTPCSE_Lagged_ALL PraisWinsten_ALL FIXED_ALL XTPCSE_EU XTPCSE_Lagged_EU PraisWinsten_EU FIXED_EU, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N)
*estout package has to be installed
*********************************************************************************************************************************************************************************************************************
*********************************************************************************************************************************************************************************************************************




*******************STATISTICAL TESTS************************************************************* 
*only for the main models with all the cases
*generaly, there is too few observation to run tests for stationarity and serial correlation

*correlation matrix
corr Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections   FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year
reg Invalidvotes_againstall MMS TheleastsquaresindexLSq sep_ballot  Concurrenceelections First_election EarlyElections   FHAVScore  Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year
vif
*ENPP correlated with FH index
hettest

*Haussman tests - Fixed vs Random
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store fixed
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, re
estimates store random
hausman fixed random
*if < 0,05, FIXED effects models should be used

*Haussman tests - Fixed vs OLS
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store fixed
reg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year
estimates store OLS
hausman fixed OLS
*if < 0,05, FIXED effects models should be used

*Breusch-Pagan Lagrange multiplier (LM)  - RANDOM vs OLS
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, re
xttest0
*if < 0,05, random effects models are appropriate

*Testing for cross-sectional dependence/contemporaneous correlation: using Breusch-Pagan LM test of independence
*a package must by installed: ssc install xttest2
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
xttest2
*Error: too few common observations across panel.
*if above 0,05 there is no cross-sectional dependence

*Testing for cross-sectional dependence/contemporaneous correlation: Using Pasaran CD test
*a package must by installed: ssc install xtcsd
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
xtcsd, pesaran abs
*error

*Stacionarity tests*
*xtserial*
xtreg Invalidvotes_againstall MMS FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
*https://www.stata.com/features/overview/panel-data-unit-root-tests/ 
*due to the unbalanced panel data, test of stacionarity are producing errors.


****DV Invalid votes (all)*****
histogram Invalidvotes_againstall
xtline Invalidvotes_againstall
xtline Invalidvotes_againstall, overlay


log close



****************************************************************************************************************************************************************************************************
****************************************************************************OTHER MODEL SPECIFIACTIONS**********************************************************************************************
****************************************************************************************************************************************************************************************************
*Models that were not used in the paper which includes different variables as well as different specification

*MODELS PRESENTED AT ECPR GENERAL CONFERENCE PRAGUE 2016*
********************************************
*DV: Invalidvotes***************************
********************************************
xtpcse Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE
xtpcse Invalidvotes lagInvalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE_Lagged
xtpcse Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
estimates store PraisWinsten
xtgls Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, panels(heteroskedastic) corr(psar1) force
estimates store FGLS
xtreg Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store FIXED
xtmixed Invalidvotes || id:
estimates store NULL
xtmixed Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year || id:
mltrsq
estimates store XTMIXED
xtmixed Invalidvotes lagInvalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year || id:
mltrsq
estimates store XTMIXED_LAGGED
******************************************
*Comparing xtpcse, prais-winsten, FGLS, xtgls, xtmixed*
estout XTPCSE XTPCSE_Lagged PraisWinsten FGLS FIXED NULL XTMIXED XTMIXED_LAGGED, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N N_l2 aic bic ll sb_rsq_l1 sb_rsq_l2 br_rsq_l1 br_rsq_l2) 

*OTHER MODELS*
xtpcse Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store ALL
xtpcse Invalidvotes  FHAVScore  EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store EARLY
xtpcse Invalidvotes  FHAVScore  Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store NO
estout ALL EARLY NO, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2)

xtreg Invalidvotes  FHAVScore  First_election EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store ALL
xtreg Invalidvotes  FHAVScore  EarlyElections Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store EARLY
xtreg Invalidvotes  FHAVScore  Concurrenceelections  sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store NO
estout ALL EARLY NO, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2)


********************************************
*DV: Invalidvotes_againstalll***************
********************************************
*HLAVNI MODEL a ROBUSTNOST CHECKS*
xtpcse Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE
xtpcse Invalidvotes_againstall lagInvalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
estimates store XTPCSE_Lagged
xtpcse Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
estimates store PraisWinsten
xtgls Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, panels(heteroskedastic) corr(psar1) force
estimates store FGLS
xtreg Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store FIXED
xtmixed Invalidvotes_againstall || id:
estimates store NULL
xtmixed Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year || id:
mltrsq
estimates store XTMIXED
xtmixed Invalidvotes_againstall lagInvalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections sep_ballot TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year || id:
mltrsq
estimates store XTMIXED_LAGGED
******************************************
*xtpcse, prais-winsten, xtgls, xtmixed*
estout XTPCSE XTPCSE_Lagged PraisWinsten FGLS FIXED NULL XTMIXED XTMIXED_LAGGED, cells(b(star fmt(3)) se(par fmt(2))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N N_l2 aic bic ll sb_rsq_l1 sb_rsq_l2 br_rsq_l1 br_rsq_l2) 



*TESTING OTHER INTERACTION EFFECTS
*************************************************************
*Intera-action Interwardemocratic_tradition_Year*
quietly xtpcse Invalidvotes IntDemTradition Year IntDemTrad_Year FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation, pairwise 
estimates store XTPCSE
quietly xtpcse Invalidvotes IntDemTradition Year IntDemTrad_Year FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation, hetonly corr(ar1) 
estimates store PraisWinsten
quietly xtgls Invalidvotes IntDemTradition Year IntDemTrad_Year FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation, panels(heteroskedastic) corr(psar1) force 
estimates store FGLS
*xtpcse, prais-winsten, xtgls*
estimates table XTPCSE PraisWinsten FGLS, star(.1 .05 .01) stats(r2, chi2)

*Marginal effect plot code
* run one of the above regression models and then run the code:
generate MV=((_n+19889)/10)
replace  MV=. if _n>2015
matrix b=e(b)
matrix V=e(V) 
scalar b1=b[1,1]
scalar b2=b[1,2]
scalar b3=b[1,3]
scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]
scalar covb1b3=V[1,3]
scalar covb2b3=V[2,3]
scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3
gen conb=b1+b3*MV if _n<2015
gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<2015
gen a=1.96*conse 
gen upper=conb+a 
gen lower=conb-a
graph twoway line conb   MV, clwidth(medium) clcolor(blue) clcolor(black)   ||   line upper  MV, clpattern(dash) clwidth(thin) clcolor(black)   ||   line lower  MV, clpattern(dash) clwidth(thin) clcolor(black)   ||   ,      xlabel(1989 1995 2000 2005 2010 2015, labsize(2.5))     ylabel(0 0.5 1, labsize(2.5))     yscale(noline) xscale(noline)    legend(col(1) order(1 2) label(1 "Marginal Effect of Interwar undemocratic tradition")      label(2 "95% Confidence Interval")   label(3 " "))  yline(0, lcolor(black))   xtitle( Year, size(3)  )   xsca(titlegap(2))   ysca(titlegap(2))    ytitle("Marginal Effect of Interwar undemocratic tradition", size(2.5))  scheme(s2mono) graphregion(fcolor(white))
drop MV conb conse a upper lower

*Interaaction Concurrence_Literacy*
quietly xtpcse Invalidvotes  Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Urbanpopulation Year, pairwise
estimates store XTPCSE
quietly xtpcse Invalidvotes  Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Urbanpopulation Year, hetonly corr(ar1)
estimates store PraisWinsten
quietly xtgls Invalidvotes Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Urbanpopulation Year, panels(heteroskedastic) corr(psar1) force
estimates store FGLS
*xtpcse, prais-winsten, xtgls*
estimates table XTPCSE PraisWinsten FGLS, star(.1 .05 .01) stats(r2, chi2)
*Marginal effect plot code
* run one of the above regression models and then run the code:
generate MV=((_n+183)/2)
replace  MV=. if _n>17
matrix b=e(b)
matrix V=e(V) 
scalar b1=b[1,1]
scalar b2=b[1,2]
scalar b3=b[1,3]
scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]
scalar covb1b3=V[1,3]
scalar covb2b3=V[2,3]
scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3
gen conb=b1+b3*MV if _n<1564
gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<100
gen a=1.96*conse 
gen upper=conb+a 
gen lower=conb-a
graph twoway line conb   MV, clwidth(medium) clcolor(blue) clcolor(black)   ||   line upper  MV, clpattern(dash) clwidth(thin) clcolor(black)   ||   line lower  MV, clpattern(dash) clwidth(thin) clcolor(black)   ||   ,      xlabel(92 94 96 98 100, labsize(2.5))     ylabel(0 2 4 6 8, labsize(2.5))     yscale(noline) xscale(noline)    legend(col(1) order(1 2) label(1 "Marginal Effect of Concurrence")      label(2 "95% Confidence Interval")   label(3 " "))  yline(0, lcolor(black))   xtitle( Literacy Rate, size(3)  )   xsca(titlegap(2))   ysca(titlegap(2))    ytitle("Marginal Effect of Concurrence", size(3))  scheme(s2mono) graphregion(fcolor(white))
drop MV conb conse a upper lower

*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************
*BASIC REGRESSION MODELS = OLS*
regress Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year
vif
hettest
regress Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year
vif
hettest

*Panel corrected errors - PCSE*
xtpcse Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
xtpcse Invalidvotes IntDemTradition Year IntDemTrad_Year IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise 
xtpcse Invalidvotes Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
xtpcse Invalidvotes Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise

xtpcse Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
xtpcse Invalidvotes_againstall IntDemTradition Year IntDemTrad_Year IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise 
xtpcse Invalidvotes_againstall  Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise
xtpcse Invalidvotes_againstall  Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, pairwise

*Prais-Winstein regression (e.g. Uggla 2008)
xtpcse Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
xtpcse Invalidvotes IntDemTradition Year IntDemTrad_Year IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1) 
xtpcse Invalidvotes Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
xtpcse Invalidvotes Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)

xtpcse Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
xtpcse Invalidvotes_againstall IntDemTradition Year IntDemTrad_Year IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1) 
xtpcse Invalidvotes_againstall  Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)
xtpcse Invalidvotes_againstall  Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, hetonly corr(ar1)

*FGLS regression (e.g. Power and Garand 2007)
xtgls Invalidvotes_againstall IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, panels(heteroskedastic) corr(psar1) force
xtgls Invalidvotes_againstall IntDemTradition Year IntDemTrad_Year FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation, panels(heteroskedastic) corr(psar1) force 
xtgls Invalidvotes_againstall Concurrenceelections Literacyrate  Concurence_Literacy IntDemTradition FHAVScore  First_election EarlyElections TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Urbanpopulation Year, panels(heteroskedastic) corr(psar1) force
xtgls Invalidvotes_againstall Effectivenumberofparliamentarypa FHAVScore FHAVScore_ENPP IntDemTradition  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, panels(heteroskedastic) corr(psar1) force

reg Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year
estimates store OLS
xtreg Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, re
estimates store XTMIXED
xtreg Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store FIXED
estimates table OLS XTMIXED FIXED, star(.1 .05 .01) stats(chi2)

*HLM MODELS
xtmixed Invalidvotes || id:
xtmixed Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year || id:
xtreg Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, fe
estimates store fixed
xtreg Invalidvotes IntDemTradition FHAVScore  First_election EarlyElections Concurrenceelections  TheleastsquaresindexLSq Effectivenumberofparliamentarypa Votedifferential1th2thin Giniindex LogGDP_per_capita GDPgrowthin Unemployment Literacyrate Urbanpopulation Year, re
estimates store random
hausman fixed random
hausman fixed random, sigmamore

*if < 0,05, FIXED effects models should be used

*
*Excluding Russia and Ukraine
drop in 130/141
*Exluding undemocratic elections
drop if FHAVScore>4


*************************************************
***********CODING********************************
*************************************************
*	Coding		
*	n	=	number of a case
*	Country	=	name of the country
*	id	=	country id number
*	panel	=	panel identification (due to early eelctions)
*	Year	=	year of the elections
*	Ctr_year	=	Country_year identificator
*	Invalidvotes	=	Number of invalid votes
*	Invalidvotes_againstall	=	Number of invalid votes and againstall votes in Russia and Ukraine
*	Turnout	=	Turnout in %
*	Rankorder	=	Rank order of the elections (1 first, 2 second etc.)
*	EarlyElections	=	Dummy indicating early elections
*	Concurrenceelections	=	Dummy indicating concurrence elections
*	PR	=	Dummy indicating PR systems
*	MMS	=	Dummy indicating MMS systems
*	Plurality	=	Dummy indicating Plurality systems
*	TheleastsquaresindexLSq	=	Gallagher least square index of disproportionality
*	Effectivenumberofelectoralpartie	=	Effective nukber of electoral parties
*	Effectivenumberofparliamentarypa	=	Effective number of parliamentary parties
*	Votedifferential1th2thin	=	Victory margin between 1th and 2th party
*	Votesharetwolargest	=	Vote share of two largest parties
*	A_1thin	=	Percentage share of the first party
*	A_2th3th	=	Ratio of share of the second / third party
*	Giniindex	=	Gini index (WB)
*	GDPpercapitaconstant_2005	=	GDP per capita (WB)
*	LogGDP_per_capita	=	logged GDP
*	GDPpercapitapreviousyear	=	GDP per capita (WB) year before elections
*	ChangeinGDP	=	chnage in GDP
*	GDPgrowthin	=	GDP growth in % (WB)
*	GDPpercapitagrowthannualWB	=	GDP annual growth in % (WB)
*	Unemployment	=	Unemployment rate % (WB)
*	Inflation	=	Inflation % (WB)
*	Literacyrate	=	Literacy rate % (WB)
*	Urbanpopulation	=	Urban population (WB)
*	Lifeexpectancyatbirthmaleyears	=	Life expectancy males (WB)
*	Lifeexpectancyatbirthfemaleyears	=	Life expectancy females (WB)
*	FHAVScore	=	Freedom House avarage score
*	FHAVScorepreviousyear	=	Freedom House avarage score previous year
*	FHchange	=	Change in FH score
*	EUmember	=	Dummy indicating EU member
*	IntDemTradition	=	The interwar democratic tradition is an index ranging from 1 to 10 as the least democratic country in the interwar period. The index is computed as the year of the breakup of democracy (Berg-Schlosser & Mitchell 2003; Moller 2014: 6) within the period of 1918 and 1939 and transformed to a 1-10-point scale. 
*	Against_all	=	Dummy against all countries
*	Y_after_First_elections	=	Years after the first elections
*	Undemocratic_elections	=	Dummy for undemocratic elections
*	FIRST_UNDEM	=	First elections under FH score higher than 4
*	GWI_index	=	Gowernment effectivness (WB)
*	TCI_index	=	Transparency international corruption index
*   VDEM_COR = corruption index by V-dem dataset (v2x_corr)
*	EthFrac	=	ethnic fragmentation (Alesina et al. 2003)
*	Volatility	=	total volatility (Chiaramonte and Emanuele 2018)
*	Pol	=	country dummy
*	CZK	=	country dummy
*	SVK	=	country dummy
*	Hungary	=	country dummy
*	Romania	=	country dummy
*	Bulgaria	=	country dummy
*	Macedonia	=	country dummy
*	Albania	=	country dummy
*	Montenegro	=	country dummy
*	Serbia	=	country dummy
*	Kosovo	=	country dummy
*	Croatia	=	country dummy
*	Slovenia	=	country dummy
*	Moldova	=	country dummy
*	Lithuania	=	country dummy
*	Latvia	=	country dummy
*	Estonia	=	country dummy
*	Ukraine	=	country dummy
*	Russia	=	country dummy
*	BaH	=	country dummy
*	First_election	=	Dummy indicating founding elections

log close
